package java04;

public class Exception01 {
    public static int divide(int x,int y){
        try{
            int result = x / y;//计算两个整数相除
            return result;
        }catch (Exception e){//对异常进行捕获处理
            System.out.println("捕获的异常信息为：" + e.getMessage());
        }finally{
            System.out.println("执行finally代码块，无论程序是否异常，都会执行！");
        }
        return -1;
    }
    public static void main(String[] args){
        int result = divide(8,0);//调用divide()方法
        if(result == -1){
            System.out.println("程序发生异常！");
        }else{
            System.out.println(result);
        }
    }
}
